//
//  Response+Rx.swift
//  SwiftNetwork
//
//  Created by GorXion on 2018/4/17.
//  Copyright © 2018年 gaoX. All rights reserved.
//

import RxSwift
import Moya

public struct BaseResponse<T: Codable>: Codable {
    var code: Int?
    var message: String?
    var result: T?
}

extension TargetType {
    public func requestWithResult<T: Codable>(_ type: T.Type) -> Single<T> {
        return request(type, atKeyPath: "result")
    }
    
    public func requestWithResponse<T: Codable>(_ type: T.Type) -> Single<BaseResponse<T>> {
        return request(BaseResponse<T>.self)
    }
}
